from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        """
        设置主窗口的布局和控件

        参数:
            MainWindow (QMainWindow): 主窗口对象
        """
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1000, 800) # 设置窗口大小
        # MainWindow.setMinimumSize(600, 400)  # 设置最小窗口大小

        # 设置窗口背景颜色
        MainWindow.setStyleSheet("background-color: #2E3440;")

        # 主窗口的中心组件
        self.screen = QtWidgets.QWidget(MainWindow)
        self.screen.setObjectName("screen")

        # 设置主布局为 QVBoxLayout
        self.mainLayout = QtWidgets.QVBoxLayout(self.screen)
        self.mainLayout.setContentsMargins(20, 20, 20, 20)
        self.mainLayout.setSpacing(20)

        # 标题部分
        self.titleLay = QtWidgets.QVBoxLayout()
        self.titleLay.setContentsMargins(0, 0, 0, 0)
        self.label = QtWidgets.QLabel()
        font = QtGui.QFont()
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setStyleSheet("color: #ECEFF4;")  # 设置标题颜色
        self.label.setObjectName("label")
        self.titleLay.addWidget(self.label)
        self.mainLayout.addLayout(self.titleLay)

        # 网格布局
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setSpacing(20)

        # 左侧按钮区域
        self.conBtnWid = QtWidgets.QWidget()
        self.conBtnWid.setMinimumSize(QtCore.QSize(200, 200))
        self.conVLay = QtWidgets.QVBoxLayout(self.conBtnWid)
        self.conVLay.setContentsMargins(0, 0, 0, 0)
        self.conVLay.setSpacing(20)

        # 关灯按钮
        self.ledOffBtn = QtWidgets.QPushButton()
        self.ledOffBtn.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        self.ledOffBtn.setFont(font)
        self.ledOffBtn.setStyleSheet(
            """
            QPushButton {
                background-color: #4C566A;
                color: #ECEFF4;
                border-radius: 10px;
                padding: 20px;
                font-size: 30px;
            }
            QPushButton:hover {
                background-color: #5E81AC;
            }
            """
        )
        self.conVLay.addWidget(self.ledOffBtn)

        # 开灯按钮
        self.ledOnBtn = QtWidgets.QPushButton()
        self.ledOnBtn.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        self.ledOnBtn.setFont(font)
        self.ledOnBtn.setStyleSheet(
            """
            QPushButton {
                background-color: #4C566A;
                color: #ECEFF4;
                border-radius: 10px;
                padding: 20px;
                font-size: 30px;
            }
            QPushButton:hover {
                background-color: #5E81AC;
            }
            """
        )
        self.conVLay.addWidget(self.ledOnBtn)
        self.gridLayout.addWidget(self.conBtnWid, 0, 0)

        # 右侧按钮区域
        self.voiceBtnWid = QtWidgets.QWidget()
        self.voiceBtnWid.setMinimumSize(QtCore.QSize(200, 200))
        self.voiceVLay = QtWidgets.QVBoxLayout(self.voiceBtnWid)

        self.voiceVLay.setContentsMargins(0, 0, 0, 0)
        self.voiceVLay.setSpacing(20)
        self.gridLayout.addWidget(self.voiceBtnWid, 0, 1)

        # 日志显示区域
        self.logShowWid = QtWidgets.QWidget()
        self.logShowWid.setMinimumSize(QtCore.QSize(400, 100))
        self.logShowVLay = QtWidgets.QVBoxLayout(self.logShowWid)
        self.logShowVLay.setContentsMargins(0, 0, 0, 0)

        # 日志输出文本框
        self.logPTE = QtWidgets.QTextEdit()
        self.logPTE.setReadOnly(True)
        logFont = QtGui.QFont()
        logFont.setPointSize(10)
        logFont.setFamily("Consolas")
        logFont.setStyle(QtGui.QFont.StyleNormal)
        self.logPTE.setFont(logFont)
        self.logPTE.setStyleSheet(
            """
            QTextEdit {
                background-color: #3B4252;
                color: #41EC44;
                border-radius: 10px;
                padding: 10px;
            }
            """
        )
        self.logShowVLay.addWidget(self.logPTE)
        self.gridLayout.addWidget(self.logShowWid, 1, 0, 1, 2)

        # 设置布局管理器的拉伸因子
        self.gridLayout.setRowStretch(0, 1)  # 第一行拉伸
        self.gridLayout.setRowStretch(1, 1)  # 第二行拉伸
        self.gridLayout.setColumnStretch(0, 1)  # 第一列拉伸
        self.gridLayout.setColumnStretch(1, 1)  # 第二列拉伸

        # 将网格布局添加到主布局
        self.mainLayout.addLayout(self.gridLayout)

        # 设置中心组件
        MainWindow.setCentralWidget(self.screen)

        # 翻译文本
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        """
        设置主窗口的翻译文本

        参数:
            MainWindow (QMainWindow): 主窗口对象
        """
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "智能家居控制"))
        self.label.setText(_translate("MainWindow", "智能家居控制"))
        self.ledOffBtn.setText(_translate("MainWindow", "关灯"))
        self.ledOnBtn.setText(_translate("MainWindow", "开灯"))
